package com.shelpe.services.sinbad.service.simbaproxy;

import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.sinbad.dto.semiauto.SemiautoSettings;
import com.shelpe.services.sinbad.entity.jpa.Adgroup;

import lombok.Data;

@FeignClient("algorithmserver")
//@FeignClient(name="algorithmserver", url="http://localhost:8091")
//@FeignClient(name="algorithmserver", url="http://sinbadgateway.shelpe.com")
public interface SemiautoClient {

	@RequestMapping(method = RequestMethod.GET, value = "/algorithmservice/semiautos/{semiautoId}")
	public SemiautoDto findSemiauto(@PathVariable("semiautoId") Long semiautoId);
	
	@RequestMapping(method = RequestMethod.POST, value = "/algorithmservice/semiautos/{semiautoId}/keywords", consumes="application/json;charset=UTF-8")
	public KeywordsDto keywords(@PathVariable("semiautoId") Long semiautoId, @RequestBody KeywordsDto dto);
	
	@Data
	public static class SemiautoDto {
		public final static int DEVICE_ALL = 0;
		public final static int DEVICE_MOBILE = 1;
		public final static int DEVICE_PC = 2;
		
		@JsonProperty("semiauto_id")
		private long autoID;
		private String title;
		private SemiautoSettings settings;
		private String status;
		private String platform;
		
		private int device;
		
		public void fromDevice(int device){
			if(device == 0){
				this.device = SemiautoDto.DEVICE_MOBILE;
			}else{
				this.device = SemiautoDto.DEVICE_PC;
			}
		}
	}
	
//	@Data
//	public static class SemiautoSettings{
//		private int date;
//	}
	
	@Data
	public static class KeywordsDto{
		@JsonProperty("adgroup_id")
		private long adgroupID;
		private List<Keyword> words;
		private Adgroup adgroup;
	}

	@Data
	public static class Keyword {
		@JsonProperty("keyword_id")
		private long keywordID;
		private String word;
		@JsonProperty("max_price")
		private float maxPrice;
		@JsonProperty("max_mobile_price")
		private float maxMobilePrice;
		@JsonProperty("impressions")
		private int impression;//展现量
		@JsonProperty("matchscope")
		private int matchScope;
		private int click;//点击量
		@JsonProperty("ctr")
		private float clickRatio;//点击率
		private float cpc;//平均点击花费
		private float cpm;
		private float cvr;//点击转化率
		@JsonProperty("avgpos")
		private int productRanking;//宝贝排名
		private int qscore;//质量得分
		@JsonProperty("wireless_qscore")
		private int mobileQscore;//移动质量得分
		private float cost;//总花费
		@JsonProperty("sales")
		private float sale;//总金额
		@JsonProperty("total_pay_count")
		private int payCount;//成交笔数
		private float roi;//投入产出比
		@JsonProperty("fav_count")
		private int favCount;//收藏数
		@JsonProperty("fav_count_rate")
		private float favCountRatio;//收藏率
		@JsonProperty("cart_count")
		private int cartCount;//购物车数
		@JsonProperty("cart_count_rate")
		private float cartCountRatio;//购物车率
		@JsonProperty("is_default_price")
		private boolean asDefaultPrice;
		@JsonProperty("is_default_mobile_price")
		private boolean asDefaultMobilePrice;

		private String action;
		@JsonProperty("new_matchscope")
		private int newMatchScope;
		@JsonProperty("new_price")
		private float price;
		@JsonProperty("new_mobile_price")
		private float mobilePrice;
		private int modifiedStatus;
		private boolean matched;
		private boolean del;
		private boolean executed;//当天是否执行过
		public boolean getAsDefaultPrice(){
			return this.asDefaultPrice;
		}
		
		public boolean getAsDefaultMobilePrice(){
			return this.asDefaultMobilePrice;
		}
		
		public void addAction(String action){
			if(this.action == null){
				this.action = action;
			}else{
				this.action = this.action + "," + action;
			}
		}
	}
}
